package com.x.Part8_多态;

/**
 * ClassName: IncomeTest
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2023/10/20 9:55
 */
public class IncomeTest {
    public static void main(String[] args) {
        //这是一个人的三种收入：直接报酬、工资收入、国务院津贴
        //{}中初始化三个收入实体对象，分别是Income类对象、Salary类对象、SpecialAllowance类对象
        Income[] incomes = new Income[]{
                new Income(3000),
                new Salary(6000),
                new SpecialAllowance(15000)
        };

        //以上结构与以下数组声明类似
        int[] arr = new int[]{1, 2, 3};

        System.out.println(totalTax(incomes));
    }
    public static double totalTax(Income[] ins){
        double total = 0.0;
        for(int i =0; i<ins.length; i++){
            total += ins[i].getTax();
        }
        return total;
    }

}
